import request from '../../utils/request';
const mod = {
  state: {

  },

  getters: {

  },

  mutations: {

  },

  actions: {
    /** 
     * 案件进程列表（管理后台）
     * caseId string 案件id
    */
    GET_CASE_PROGRESS_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/case/caseProgress.htm', payload).then(res => {
          console.log('res::', res);
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);
          reject(err);
        })
      });
    },
    /**
     * 获取案件列表
     * 案件状态 tendering("招标中"), solving("进行中"), done("结束")， delete("作废")
     * @payload{
     *  userId   string
     *  caseId   string
     *  pageNum  string 
     *  province string 
     *  city     string 
     *  startDay string 
     *  endDay   string 
     *  userMobileNo string
     *  lawyerMobileNo string
     *  lawyerName string
     * }
     * 
     * @result object 
     * payState string  支付状态，unpaid("未支付"), paid("已支付"),
     * */
    GET_CASE_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/case/caseList.htm', payload).then(res => {
          console.log('res::', res);
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);
          reject(err);
        })
      });
    },

    /**
     * 新增案件 
     * @params layload{
     *  userId string 
     *  province string  省id
     *  city string  城市id
     *  caseType string 案件类型
     *  title string 
     *  content string 
     *  lawyerId string
     * }
     * */
    ADD_CASE({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/case/addCase.htm', payload).then(res => {
          console.log('res::', res);
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);
          reject(err);
        })
      });
    },

    /**
     * 案件管理-更换律师/案件结束/作废
     * @params payload{
     *  caseId string
     *  lawyerId string 
     *  state string done("结束"), delete("作废");
     * }
     * */
    UPDATE_CASE({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/case/update.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);
          reject(err);
        })
      });
    },

    /**
     * 案件管理-添加进度
     * @params payload{
     *  caseId string 案件id
     *  title string 
     *  content string 
     *  picUrl string
     *  money  string 
     *  createTime string
     * }
     * */
    ADD_CASE_PROGRESS({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/case/addProgress.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);
          reject(err);
        })
      });
    },

    /**
     * 案件管理-编辑进度
     * @params payload{
     *  id    string 进程id
     *  caseType string 案件类型
     *  title string 
     *  content string 
     *  picUrl string
     *  money  string 
     *  payState string  支付状态，unpaid("未支付"), paid("已支付"),
     *  createTime string
     *  state string  normal("正常"), deleted("已删除");
     *  lawyerId string 律师id
     * }
     * */
    UPDATE_CASE_PROGRESS({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/case/editProgress.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);
          reject(err);
        })
      });
    },



    /**
     * 获取分类列表
    */
    GET_CASE_TYPE_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseType/list.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);
          reject(err);
        })
      });
    },

    /**
     * 分类管理-新增/更新/删除分类
     * @params payload{
     *  name string 分类标题
     *  remark string 备注
     *  icon string 图标 
     *  idDelete string 是否删除 1是0否
     *  id string 分类id，为null新增，否则为修改
     * }
    */
    HANDLE_CASE_TYPE({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseType/save.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);
          reject(err);
        })
      });
    },

    /**
     * 分类管理-获取分类详情
     * @params payload{
     *  id string 
     * }
    */
    GET_CASE_TYPE_DETAIL({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseType/detail.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);
          reject(err);
        })
      });
    }

  }
}

export default mod